<script setup>
import {
    Edit, Delete, Link, Download,
} from '@element-plus/icons-vue'
import axios from 'axios';
import { ref } from 'vue'
import { ElMessage, ElMessageBox, ElUpload } from 'element-plus'
import {
    inquiryProductionPSservice,
} from '@/api/book.js'

//控制添加分类弹窗
const dialogVisible = ref(false)
//分页条数据模型
//const pageNum = ref(1)//当前页
const total = ref(20)//总条数
//const pageSize = ref(3)//每页条数
//文章分类数据模型

//定义变量，控制标题
const title = ref('')
const title2 = ref('上传附件')
//交通路线列表数据模型
const majors = ref([
    { id: 11 }, { id: 23 }
])

const formref = ref(null); //表单校验
//与后端交互的json数据
const pathmodel = ref({
    name: null,
    weight: null,
    model: null,
    cycle: null,
    size: null,
    comment: null,
    price: null,
    number: null,
    isdull: null,
    figurenumber: null,
    material: null,
    type: '单体设备' //没用
})

const findmodel = ref({
    pageNum: 1,
    pageSize: 5,
    str: '',
    findType: '单体设备'
})

const stafflist = async () => {
    console.log(findmodel.value);
    let result = await inquiryProductionPSservice(findmodel.value); //写在价格本里面的，controller也是
    console.log(result);
    total.value = result.data.total;
    majors.value = result.data.items;
}
stafflist();
//当每页条数发生了变化，调用此函数
const onSizeChange = (size) => {
    findmodel.value.pageSize = size;
    stafflist();
}
//当前页码发生变化，调用此函数
const onCurrentChange = (num) => {
    findmodel.value.pageNum = num;
    stafflist();
}
const cleardata = () => {
    findmodel.value.str = ''
}
//表单校验
const rules = {
    name: [
        { required: true, message: '请输入名称', trigger: 'blur' },
    ],
    weight: [
        { required: true, message: '请输入重量', trigger: 'blur' },
    ],
    model: [
        { required: true, message: '请输入型号', trigger: 'blur' },
    ],
    cycle: [
        { required: true, message: '请输入交货周期', trigger: 'blur' },
    ],
    size: [
        { required: true, message: '请输入尺寸', trigger: 'blur' },
    ],
    comment: [
        { required: true, message: '请输入备注', trigger: 'blur' },
    ],
    productionid: [
        { required: true, message: '请选择产品', trigger: 'blur' },
    ],
    price: [
        { required: true, message: '请输入价格', trigger: 'blur' },
    ],
    number: [
        { required: true, message: '请输入数量', trigger: 'blur' },
    ],
    isdull: [
        { required: true, message: '请选择是否呆滞', trigger: 'blur' },
    ],
    figurenumber: [
        { required: true, message: '请输入图号', trigger: 'blur' },
    ],
    material: [
        { required: true, message: '请输入材料', trigger: 'blur' },
    ],
}
//展示编辑弹窗
const showDialog = (row) => {
    title.value = '产品详细信息';
    dialogVisible.value = true;
    //数据拷贝
    Object.keys(row).forEach((key) => {
        pathmodel.value[key] = row[key];
    });
}

</script>

<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>销售库存查询</span>
                <div class="extra">
                    <!-- <el-button type="primary" @click="add">添加客户</el-button> -->
                </div>
            </div>
        </template>
        <!-- 搜索表单 -->
        <el-form>
            <el-form-item label="查询条件:">
                <el-input v-model="findmodel.str" placeholder="请输入查询内容" style="width: 300px"></el-input>
                <el-button type="primary" @click="stafflist" style="margin-left: 15px;">搜索</el-button>
                <el-button @click="cleardata">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="majors" style="width: 100%">
            <el-table-column label="名称" prop="name"></el-table-column>
            <el-table-column label="型号" prop="model"></el-table-column>
            <el-table-column label="数量" prop="number"></el-table-column>
            <el-table-column label="价格" prop="price"></el-table-column>
            <el-table-column label="图号" prop="figurenumber"></el-table-column>
            <el-table-column label="材料" prop="material"></el-table-column>
            <el-table-column label="是否呆滞" prop="isdull"></el-table-column>
            <el-table-column label="所属部门" prop="department"></el-table-column>
            <el-table-column label="操作" width="120">
                <template #default="{ row }">
                    <!-- <el-button :icon="Download" circle plain type="success" @click="download(row)"></el-button> -->
                    <!-- <el-button :icon="Link" circle plain type="info" @click="showDialogupload(row)"></el-button> -->
                    <el-button :icon="Edit" plain type="primary" @click="showDialog(row)">查看详情</el-button>
                    <!-- <el-button :icon="Delete" circle plain type="danger" @click="del(row)"></el-button> -->
                </template>
            </el-table-column>
            <template #empty>
                <el-empty description="没有数据" />
            </template>
        </el-table>
        <!-- 分页条 -->
        <el-pagination v-model:current-page="findmodel.pageNum" v-model:page-size="findmodel.pageSize"
            :page-sizes="[5, 10, 15, 20]" layout="jumper, total, sizes, prev, pager, next" background :total="total"
            @size-change="onSizeChange" @current-change="onCurrentChange"
            style="margin-top: 20px; justify-content: flex-end" />
    </el-card>

    <!-- 添加分类弹窗 -->
    <el-dialog v-model="dialogVisible" :title="title" width="40%">
        <el-form :model="pathmodel" ref="formref" :rules="rules" label-width="81px" style="padding-right: 30px">
            <el-row gutter="20">
                <el-col :span="12">
                    <el-form-item label="名称" prop="name">
                        <el-input disabled v-model="pathmodel.name"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="重量" prop="weight">
                        <el-input disabled v-model="pathmodel.weight"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row gutter="20">
                <el-col :span="12">
                    <el-form-item label="型号" prop="model">
                        <el-input disabled v-model="pathmodel.model"></el-input>
                    </el-form-item>
                </el-col>

                <el-col :span="12">
                    <el-form-item label="尺寸" prop="size">
                        <el-input disabled v-model="pathmodel.size"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row gutter="20">
                <el-col :span="12">
                    <el-form-item label="交货周期" prop="cycle">
                        <el-input disabled v-model="pathmodel.cycle"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="备注" prop="comment">
                <el-input disabled type="textarea" :rows="4" v-model="pathmodel.comment"
                    style="width: 500px"></el-input>
            </el-form-item>
            <el-row gutter="20">
                <el-col :span="12">
                    <el-form-item label="图号" prop="figurenumber">
                        <el-input disabled v-model="pathmodel.figurenumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="材料" prop="material">
                        <el-input disabled v-model="pathmodel.material"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row gutter="20">
                <el-col :span="12">
                    <el-form-item label="数量" prop="number">
                        <el-input disabled v-model="pathmodel.number" type="number"></el-input>
                    </el-form-item>
                </el-col>

                <el-col :span="12">
                    <el-form-item label="价格" prop="price">
                        <el-input disabled v-model="pathmodel.price" type="number"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row gutter="20">
                <el-col :span="12">
                </el-col>
                <el-col :span="12">
                    <el-form-item label="是否呆滞" prop="isdull">
                        <el-radio disabled label="是" v-model="pathmodel.isdull">是</el-radio>
                        <el-radio disabled label="否" v-model="pathmodel.isdull">否</el-radio>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <!-- <template #footer>
            <span class="dialog-footer">
                <el-button @click="dialogVisible = false">取消</el-button>
                <el-button type="primary" @click="addorupdate"> 确认 </el-button>
            </span>
        </template> -->
    </el-dialog>

</template>

<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    box-sizing: border-box;

    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
}
</style>